import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


 class Prologue extends JFrame {

	private JPanel PrologueContent;
	public int PlayerNum,readyCheck=4;
	public Deck deck;
	public Prologue Here;
	public PlayerInterface[] Players=new PlayerInterface[4];
	
	/**
	 * Create the frame.
	 */
	Prologue() {
		Here=this;
		setResizable(false);
		setTitle("Poker");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(350, 50, 600, 600);
		PrologueContent = new JPanel();
		PrologueContent.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(PrologueContent);
		PrologueContent.setLayout(null);
		
		JLabel Welcome = new JLabel("Welcome in Poker Game");
		Welcome.setFont(new Font("Tahoma", Font.PLAIN, 25));
		Welcome.setBounds(162, 11, 354, 87);
		PrologueContent.add(Welcome);
		
		JTextArea Version = new JTextArea();
		Version.setBackground(UIManager.getColor("Button.background"));
		Version.setFont(new Font("Monospaced", Font.PLAIN, 11));
		Version.setText("1.0 version by Micha\u0142 Nguyen Anh & Pawe\u0142 Olszowski");
		Version.setBounds(230, 545, 354, 16);
		PrologueContent.add(Version);
		
		JTextArea txtrPleaseSelectPlayers = new JTextArea();
		txtrPleaseSelectPlayers.setEditable(false);
		txtrPleaseSelectPlayers.setFont(new Font("Monospaced", Font.PLAIN, 15));
		txtrPleaseSelectPlayers.setBackground(UIManager.getColor("Button.background"));
		txtrPleaseSelectPlayers.setText("Please select players number");
		txtrPleaseSelectPlayers.setBounds(172, 123, 275, 37);
		PrologueContent.add(txtrPleaseSelectPlayers);
		
		deck=new Deck();
		deck.shuffleDeck();
		Card card=new Card();
		
		JButton Player1 = new JButton("1 Player");
		Player1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				PlayerNum = 1;
				setVisible(false);
				Table frame = new Table();
				frame.setVisible(true);
				PlayerInterface PlayerPanel1 = new PlayerInterface(1,0,Here);
				frame.getContentPane().add(PlayerPanel1);
				Here.Players[0]=PlayerPanel1;
				
				PlayerInterface PlayerPanel2 = new PlayerInterface(1,1,Here);
				frame.getContentPane().add(PlayerPanel2);
				PlayerPanel2.Exchange.setEnabled(false);
				PlayerPanel2.Ready.setEnabled(false);
				Here.Players[1]=PlayerPanel2;
				
				PlayerInterface PlayerPanel3 = new PlayerInterface(2,1,Here);
				frame.getContentPane().add(PlayerPanel3);
				PlayerPanel3.Exchange.setEnabled(false);
				PlayerPanel3.Ready.setEnabled(false);
				Here.Players[2]=PlayerPanel3;
				
				PlayerInterface PlayerPanel4 = new PlayerInterface(3,1,Here);
				frame.getContentPane().add(PlayerPanel4);
				PlayerPanel4.Exchange.setEnabled(false);
				PlayerPanel4.Ready.setEnabled(false);
				Here.Players[3]=PlayerPanel4;
				
				int x=0,counter[]={0,0,0,0};
				for(int i=0;i<20;i++) {
					x=i%4;
					switch (x)
					{
						case 0:
							PlayerPanel1.hand[counter[0]]=deck.getCard();
							counter[0]++;
							break;
						case 1:
							PlayerPanel2.hand[counter[1]]=deck.getCard();
							counter[1]++;
							break;
						case 2:
							PlayerPanel3.hand[counter[2]]=deck.getCard();
							counter[2]++;
							break;
						case 3:
							PlayerPanel4.hand[counter[3]]=deck.getCard();
							counter[3]++;
							break;
					}
				}
				PlayerPanel1.sortHand();
				PlayerPanel2.sortHand();
				PlayerPanel3.sortHand();
				PlayerPanel4.sortHand();
				
				PlayerPanel1.loadHand();
				PlayerPanel2.loadHand();
				PlayerPanel3.loadHand();
				PlayerPanel4.loadHand();
			}
		});
		Player1.setBounds(196, 190, 89, 23);
		PrologueContent.add(Player1);
		
		JButton Player2 = new JButton("2 Players");
		Player2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				PlayerNum = 2;
				setVisible(false);
					Table frame = new Table();
					frame.setVisible(true);
					PlayerInterface PlayerPanel1 = new PlayerInterface(1,0,Here);
					frame.getContentPane().add(PlayerPanel1);
					Players[0]=PlayerPanel1;
					
					PlayerInterface PlayerPanel2 = new PlayerInterface(2,0,Here);
					frame.getContentPane().add(PlayerPanel2);
					Players[1]=PlayerPanel2;
					
					PlayerInterface PlayerPanel3 = new PlayerInterface(1,1,Here);
					frame.getContentPane().add(PlayerPanel3);
					PlayerPanel3.Exchange.setEnabled(false);
					PlayerPanel3.Ready.setEnabled(false);
					Players[2]=PlayerPanel3;
					
					PlayerInterface PlayerPanel4 = new PlayerInterface(2,1,Here);
					frame.getContentPane().add(PlayerPanel4);
					PlayerPanel4.Exchange.setEnabled(false);
					PlayerPanel4.Ready.setEnabled(false);
					Players[3]=PlayerPanel4;
					
					int x=0,counter[]={0,0,0,0};
					for(int i=0;i<20;i++) {
						x=i%4;
						switch (x)
						{
							case 0:
								PlayerPanel1.hand[counter[0]]=deck.getCard();
								counter[0]++;
								break;
							case 1:
								PlayerPanel2.hand[counter[1]]=deck.getCard();
								counter[1]++;
								break;
							case 2:
								PlayerPanel3.hand[counter[2]]=deck.getCard();
								counter[2]++;
								break;
							case 3:
								PlayerPanel4.hand[counter[3]]=deck.getCard();
								counter[3]++;
								break;
						}
					}
					PlayerPanel1.sortHand();
					PlayerPanel2.sortHand();
					PlayerPanel3.sortHand();
					PlayerPanel4.sortHand();
					
					PlayerPanel1.loadHand();
					PlayerPanel2.loadHand();
					PlayerPanel3.loadHand();
					PlayerPanel4.loadHand();
			}
		});
		Player2.setBounds(321, 190, 89, 23);
		PrologueContent.add(Player2);
		
		JButton Player3 = new JButton("3 Players");
		Player3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				PlayerNum = 3;
					setVisible(false);
					Table frame = new Table();
					frame.setVisible(true);
					PlayerInterface PlayerPanel1 = new PlayerInterface(1,0,Here);
					frame.getContentPane().add(PlayerPanel1);
					Players[0]=PlayerPanel1;
					
					PlayerInterface PlayerPanel2 = new PlayerInterface(2,0,Here);
					frame.getContentPane().add(PlayerPanel2);
					Players[1]=PlayerPanel2;
					
					PlayerInterface PlayerPanel3 = new PlayerInterface(3,0,Here);
					frame.getContentPane().add(PlayerPanel3);
					Players[2]=PlayerPanel3;
					
					PlayerInterface PlayerPanel4 = new PlayerInterface(1,1,Here);
					frame.getContentPane().add(PlayerPanel4);
					PlayerPanel4.Exchange.setEnabled(false);
					PlayerPanel4.Ready.setEnabled(false);
					Players[3]=PlayerPanel4;
					
					int x=0,counter[]={0,0,0,0};
					for(int i=0;i<20;i++) {
						x=i%4;
						switch (x)
						{
							case 0:
								PlayerPanel1.hand[counter[0]]=deck.getCard();
								counter[0]++;
								break;
							case 1:
								PlayerPanel2.hand[counter[1]]=deck.getCard();
								counter[1]++;
								break;
							case 2:
								PlayerPanel3.hand[counter[2]]=deck.getCard();
								counter[2]++;
								break;
							case 3:
								PlayerPanel4.hand[counter[3]]=deck.getCard();
								counter[3]++;
								break;
						}
					}
					PlayerPanel1.sortHand();
					PlayerPanel2.sortHand();
					PlayerPanel3.sortHand();
					PlayerPanel4.sortHand();
					
					PlayerPanel1.loadHand();
					PlayerPanel2.loadHand();
					PlayerPanel3.loadHand();
					PlayerPanel4.loadHand();
			}
		});
		Player3.setBounds(196, 247, 89, 23);
		PrologueContent.add(Player3);
		
		JButton Player4 = new JButton("4 Players");
		Player4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				PlayerNum = 4;
					setVisible(false);
					Table frame = new Table();
					frame.setVisible(true);
					PlayerInterface PlayerPanel1 = new PlayerInterface(1,0,Here);
					frame.getContentPane().add(PlayerPanel1);
					Players[0]=PlayerPanel1;
					
					PlayerInterface PlayerPanel2 = new PlayerInterface(2,0,Here);
					frame.getContentPane().add(PlayerPanel2);
					Players[1]=PlayerPanel2;
					
					PlayerInterface PlayerPanel3 = new PlayerInterface(3,0,Here);
					frame.getContentPane().add(PlayerPanel3);
					Players[2]=PlayerPanel3;
					
					PlayerInterface PlayerPanel4 = new PlayerInterface(4,0,Here);
					frame.getContentPane().add(PlayerPanel4);
					Players[3]=PlayerPanel4;
					
					int x=0,counter[]={0,0,0,0};
					for(int i=0;i<20;i++) {
						x=i%4;
						switch (x)
						{
							case 0:
								PlayerPanel1.hand[counter[0]]=deck.getCard();
								counter[0]++;
								break;
							case 1:
								PlayerPanel2.hand[counter[1]]=deck.getCard();
								counter[1]++;
								break;
							case 2:
								PlayerPanel3.hand[counter[2]]=deck.getCard();
								counter[2]++;
								break;
							case 3:
								PlayerPanel4.hand[counter[3]]=deck.getCard();
								counter[3]++;
								break;
						}
					}
					PlayerPanel1.sortHand();
					PlayerPanel2.sortHand();
					PlayerPanel3.sortHand();
					PlayerPanel4.sortHand();
					
					PlayerPanel1.loadHand();
					PlayerPanel2.loadHand();
					PlayerPanel3.loadHand();
					PlayerPanel4.loadHand();
			}
		});
		Player4.setBounds(321, 247, 89, 23);
		PrologueContent.add(Player4);
		
	}
}
